Passed
Branch master (b0d099)
by Markus
03:49
created

script.js ➔ toggleBeta   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 13
rs 9.2
1
function toggleClassElement(class_name, element)
2
{
3
    if (element.className.indexOf(class_name) != -1) {
4
        // class already there, remove it
5
        element.className = element.className.replace(class_name, '').trim();
6
    } else {
7
        // class not there, add it
8
        element.className += ' ' + class_name;
9
    }
10
}
11
12
function toggleClass(class_name, element_ids)
13
{
14
    for (var i in element_ids) {
15
        if (!element_ids.hasOwnProperty(i)) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
16
        var element = document.getElementById(element_ids[i]);
17
        toggleClassElement(class_name, element);
18
    }
19
}
20
21
function toggleBeta()
22
{
23
    var input_element = document.getElementById('switch-beta');
24
    var elements = document.getElementsByClassName('spk-beta');
25
    var newState = "none";
26
    if (input_element.checked) {
27
        newState = "";
28
    }
29
    for (var i in elements) {
30
        if (!elements.hasOwnProperty(i)) continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
31
        elements[i].style.display = newState;
32
    }
33
}
34
35
function toggleDetails(clicked_element)
36
{
37
    var card = clicked_element.parentElement.parentElement;
38
    var details = card.getElementsByClassName('spk-details')[0];
39
    toggleClassElement('spk-details-hidden', details);
40
    if (details.className.indexOf('spk-details-hidden') == -1) {
41
        // Details now visible
42
        clicked_element.innerHTML = 'Hide Info';
43
    } else {
44
        // Details now hidden
45
        clicked_element.innerHTML = 'More Info';
46
    }
47
}
48